package com.hugothauan.cowboyshoot;




import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.pm.ActivityInfo;

public class Menu extends Activity {

	private final String TAG = "Menu";
	private MenuView menuView;
	private BluetoothAdapter btAdapter;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Screen adjustments
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);	
		
		// Finish the splash activity to don't get back to it when press BACK from the Menu Activity
		MinhasCoisas.getCurrentActivity().finish();
		
		MinhasCoisas.setCurrentActivity(this);
		
		// if orientation is vertical
		if(getResources().getConfiguration().orientation == 1)
		{
			MinhasCoisas.setAbriuActivity(true);
			Log.i(TAG, "Orientacao PORTRAIT");
			
		}else
		{
			MinhasCoisas.setAbriuActivity(false);
		}
		
		Create();
		
	}
	
	@Override
	protected void onStart()
	{
		super.onStart();
		Start();

	}
	

	public void Create()
	{
		if(MinhasCoisas.isAbriuActivity())
		{
			// onCreate things
			Log.i(TAG, "CREATE");
			
			btAdapter = BluetoothAdapter.getDefaultAdapter();

			MinhasCoisas.setCurrentActivity(this);
			menuView = new MenuView(this, btAdapter);
			setContentView(menuView);
		}
	}
	
	public void Start()
	{
		if(MinhasCoisas.isAbriuActivity())
		{
			// onStart things
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	    
	    if (requestCode == REQUEST.REQUEST_ENABLE_BT) {
	        
	        if (resultCode == RESULT_OK) {
	        	
	        	// Change Activity for Select Device Activity
	        	MinhasCoisas.ChangeActivity(DeviceList.class);			
	        }
	    }
	}
	@Override
	public void onDestroy()
	{
		super.onDestroy();
		//this.cenaDeJogo.SetAlive(false);
		
		this.menuView.SetAlive(false);
		BluetoothAdapter.getDefaultAdapter().disable();
	}
}
